package com.ruoyi.fireman.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.fireman.mapper.TMenuMapper;
import com.ruoyi.fireman.domain.TMenu;
import com.ruoyi.fireman.service.ITMenuService;
import com.ruoyi.common.core.text.Convert;

/**
 * 首页菜单Service业务层处理
 *
 * @author ruoyi
 * @date 2021-08-24
 */
@Service
public class TMenuServiceImpl extends ServiceImpl<TMenuMapper, TMenu> implements ITMenuService {
    @Autowired
    private TMenuMapper tMenuMapper;

    /**
     * 查询首页菜单
     *
     * @param id 首页菜单主键
     * @return 首页菜单
     */
    @Override
    public TMenu selectTMenuById(Long id) {
        return tMenuMapper.selectTMenuById(id);
    }

    /**
     * 查询首页菜单列表
     *
     * @param tMenu 首页菜单
     * @return 首页菜单
     */
    @Override
    public List<TMenu> selectTMenuList(TMenu tMenu) {
        return tMenuMapper.selectTMenuList(tMenu);
    }

    @Override
    public List<TMenu> selectOneTMenuList(List<String> positions) {
        return tMenuMapper.selectOneTMenuList(positions);
    }

    @Override
    public TMenu selectMiddleMenu() {
        QueryWrapper<TMenu> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(TMenu::getPosition, "7");
        return this.getOne(queryWrapper);
    }

    @Override
    public List<TMenu> selectTMenus(String... positions) {
        QueryWrapper<TMenu> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().in(TMenu::getPosition, positions).orderByAsc(TMenu::getCreateTime);
        return this.list(queryWrapper);
    }

    /**
     * 新增首页菜单
     *
     * @param tMenu 首页菜单
     * @return 结果
     */
    @Override
    public int insertTMenu(TMenu tMenu) {
        tMenu.setCreateTime(DateUtils.getNowDate());
        return tMenuMapper.insertTMenu(tMenu);
    }

    /**
     * 修改首页菜单
     *
     * @param tMenu 首页菜单
     * @return 结果
     */
    @Override
    public int updateTMenu(TMenu tMenu) {
        tMenu.setUpdateTime(DateUtils.getNowDate());
        return tMenuMapper.updateTMenu(tMenu);
    }

    /**
     * 批量删除首页菜单
     *
     * @param ids 需要删除的首页菜单主键
     * @return 结果
     */
    @Override
    public int deleteTMenuByIds(String ids) {
        return tMenuMapper.deleteTMenuByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除首页菜单信息
     *
     * @param id 首页菜单主键
     * @return 结果
     */
    @Override
    public int deleteTMenuById(Long id) {
        return tMenuMapper.deleteTMenuById(id);
    }
}
